import StepHeader from "@page/cart/comps/StepHeader";
import { default as U } from "@module/Uts";
import StepThree from "./comps/StepThree";
import StepFour from "./comps/StepFour";
import "./orderresult.css";
import ZenUI from "@root/components/ZenUI/ZenUI";

export default class OrderResults extends React.Component {
  constructor() {
    super();
    let POrderResult = U.storage.get("POrderResult") || {};
    this.suppMsgs = POrderResult.suppMsgs;
    this.orderId = POrderResult.id;

    this.state = {
      step: 3
    };
  }

  componentDidMount() {
    if (!this.suppMsgs) {
      ZenUI.ST("页面信息已过期，自动跳转到首页", 2);
      setTimeout(() => {
        $state.go({
          stateName: "/"
        });
      }, 2000);
    }
  }

  render() {
    const { step } = this.state;
    return (
      <div>
        <StepHeader step={step} />
        {this.renderCenter()}
      </div>
    );
  }

  renderCenter() {
    const step = $state.params.step || this.state.step;
    if (!this.suppMsgs) {
      return <div style={{ height: 200 }} />;
    }
    if (step == 3) {
      return (
        <StepThree
          orderId={this.orderId}
          setStep={() => {
            $state.to(
              "/orderResults/?step=4&isGroupbuying=" +
                $state.params.isGroupbuying
            );
          }}
          suppMsgs={this.suppMsgs}
        />
      );
    } else if (step == 4) {
      return <StepFour orderId={this.orderId} suppMsgs={this.suppMsgs} />;
    }
    return null;
  }
}
